#pragma once

#include "player.h"

#include <QtCore/QObject>

class GameHandlerPrivate;

class GameHandler : public QObject
{
    Q_OBJECT

public:
    static const unsigned MAX_PLAYERS = 4;

    GameHandler();
    ~GameHandler();

    const Player &player(int index) const;
    const Scene *scene() const;
    bool locked() const;

    /**
     * @brief addPlayer try to add player for next game
     * @param player - copyable player
     * @return returns -1 if game started or players count is maximum, returns
     * player index otherwise
     */
    int addPlayer(const Player &player);

    /**
     * @brief set game scene size
     * @return false if game startedw
     */
    bool setSize(unsigned width, unsigned height);

    /**
     * @brief setInterval set game timer interval
     * @param interval - turn time in milliseconds
     * @return false if game started
     */
    bool setInterval(unsigned interval);

    /**
     * @brief startGame
     * @return
     */
    bool startGame();

public slots:
    void onTimer();
    void onBonusTimer();

signals:
    void gameStart();
    void turnEnd();
    void gameEnd();

private:
    GameHandlerPrivate *d;
};
